<template>
  <a-spin :spinning="spinning != 0">
    <a-form :form="form"
            layout="horizontal"
            :hideRequiredMark="false">
      <a-form-item :label="$t('m.system.sysconfig.entity.configCode')" :label-col="{ span:4 }" :wrapper-col="{ span:18 }">
        <a-input
          style="width:100%"
          :disabled="disabledRules.configCode"
          placeholder=""
          type="text"
          v-decorator="['configCode', validatorRules.configCode]"
        />
      </a-form-item>
      <a-form-item :label="$t('m.system.sysconfig.entity.configName')" :label-col="{ span:4 }" :wrapper-col="{ span:18 }">
        <a-input
          style="width:100%"
          :disabled="disabledRules.configName"
          placeholder=""
          type="text"
          v-decorator="['configName', validatorRules.configName]"
        />
      </a-form-item>
      <a-form-item :label="$t('m.system.sysconfig.entity.configValue')" :label-col="{ span:4 }" :wrapper-col="{ span:18 }">
        <a-input
          style="width:100%"
          :disabled="disabledRules.configValue"
          placeholder=""
          type="text"
          v-decorator="['configValue', validatorRules.configValue]"
        />
      </a-form-item>
      <a-form-item v-if="this.model.configCode=='project-logo-url'" :label="$t('m.common.button.upload_pic')" :label-col="{ span:4 }" :wrapper-col="{ span:18 }">
        <UploadImg
            :record="uploadRecord"
            @change="change"
                    />
      </a-form-item>
    </a-form>
  </a-spin>
</template>

<script>

  import { FormMixin } from '@/mixins/FormMixin'
  import YchConstant from "@/api/YchConstant";
  import UploadImg from '@/views/eform/modules/designer/packages/UploadImg'

  export default {
    name: 'SysconfigformModal',
    mixins: [FormMixin],
    components: {
      UploadImg
    },
    data () {
      return {
        validatorRules: {
          configName: {
            rules: [{ 'message': this.$t('m.common.tip.verify_required'), 'required': true }]
          },
          configCode: {
            rules: [{ 'message': this.$t('m.common.tip.verify_required'), 'required': true }]
          },
          configValue: {
            // rules: [{ 'message': this.$t('m.common.tip.verify_required'), 'required': true }]
          },
        },
        disabledRules: {
          configName: true,
          configCode: true,
          configValue: false,
        },
        url: {
          queryById: YchConstant.PREFIX_SYSTEM + '/sysconfig/queryById',
          edit: YchConstant.PREFIX_SYSTEM + '/sysconfig/edit',
        },
        uploadRecord:
        {
            options:
                {
                      defaultValue: "",
                      multiple: false,
                       disabled:false,
                      bizPath: "",
                      limit: 1,
                      listType: "picture-card"
                },
        },
      }
    },
   methods: {
       change(arg){
         if(arg){
           let list = JSON.parse(arg)
           if(list && list.length>0)
           {
             let url = list[0].url
             this.form.setFieldsValue({ configValue: url })
           }
         }
       },
   },
  }

</script>
